import  express ,{Application,Request,Response} from "express";
import index from './index/index'
import indexUpload from './index/indexUpload'
import cors from 'cors';
const app = express();
app.use(cors()) //在所有路由之前使用跨域
app.use(index);
app.use(indexUpload)
app.use(express.json())
app.use(express.urlencoded({extended:false}))
app.use(express.static('./public'))

app.get("/",(req,res)=>{

    res.send("success");
})
const port = 3000;
app.get("/test",(req,res)=>{
    res.send({
        msg:"跨域成功111"
    })
})
app.use((err:any,req:any,res:any,next:any)=>{
//    console.log(err.name)
   if(err.name === "MulterError"){
    // console.log(err.message)
    return res.send({
        status : 400,
        msg : "上传文件失败"
    })
   }
   return res.send({
    msg:"未知错误"
   })

})
app.listen(port,()=>{
    console.log("http://localhost:3000");
})